package cuiyt.leetcode.dichotomy.demob;

/**
 * @author cyt
 * @create 2020-09-06 16:18
 */
public class Tc {
    public static void main(String[] args) {

    }

    public int findPeakElement(int[] nums) {
        /*
        特判
         */
        int l = 0;
        int mid = 0;
        int r = nums.length - 1;
        if (nums.length == 1) {
            return 0;
        }
        while (l <= r) {
            mid = l + (r - l) / 2;
            /**
             * 当前二分点为最左边， 或者大于左边值
             * 当前二分点为最右边， 或者大于右边值
             */
            if ((mid == 0 || nums[mid] >= nums[mid - 1]) && (mid == r || nums[mid] >= nums[mid + 1])) {
                return mid;
            } else if (mid > 0 && nums[mid - 1] > nums[mid]) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return mid;
    }
}
